/*
DNES replication material for:
"Personality and Roots of Welfare State Support: How Openness to Experience Moderates the Influence of Self-Interest and Ideology on Redistributive Preferences"

Authors: Tobias Heide-Jørgensen, Peter Thisted Dinesen, and Kim Mannemar Sønderskov.

PURPOSE: Reproducing results based on DNES data (Figure F.1 in the Online Appendix).
*/

*DNES 2001	
use "DNES2001_data.dta",clear	

gen dk_pinc = 0
replace dk_pinc = 1 if V273==18
gen dk_hinc = 0
replace dk_hinc = 1 if V274==18

label var dk_pinc "Personal income"
label var dk_hinc "Household income"

rename (dk_pinc dk_hinc) (inc#), addnumber
gen n = _n
reshape long inc, i(n)
label define _j 1 "Personal income" 2 "Household income"
label values _j _j

prtest inc,by(_j)

statsby mean=r(mean) ub=r(ub) lb=r(lb) N=r(N), by(_j) clear: ci mean inc
mylabels 0(5)15, myscale(@/100) local(yaxis) suffix("%")
twoway bar mean _j, color(gs12) barw(0.5) || rcap ub lb _j, legend(off) ylabel(`yaxis',grid gmax gmin angle(h) labsize(small)) xtitle("") xscale(range(0.6 2.4))  xlabel(1 "Personal income" 2 "Household income",labsize(small)) scheme(plotplain) ytitle("") title(2001) saving(DNES01, replace)

*DNES 2005
use "DNES2005_data.dta",clear	

gen dk_pinc = 0
replace dk_pinc = 1 if V333==88
gen dk_hinc = 0
replace dk_hinc = 1 if V334==88

label var dk_pinc "Personal income"
label var dk_hinc "Household income"
	
rename (dk_pinc dk_hinc) (inc#), addnumber
gen n = _n
reshape long inc, i(n)
label define _j 1 "Personal income" 2 "Household income"
label values _j _j

prtest inc,by(_j)

statsby mean=r(mean) ub=r(ub) lb=r(lb) N=r(N), by(_j) clear: ci mean inc
mylabels 0(5)15, myscale(@/100) local(yaxis) suffix("%")
twoway bar mean _j, color(gs12) barw(0.5) || rcap ub lb _j, legend(off) ylabel(`yaxis',grid gmax gmin angle(h) labsize(small)) xtitle("") xscale(range(0.6 2.4))  xlabel(1 "Personal income" 2 "Household income",labsize(small)) scheme(plotplain) ytitle("") title(2005) saving(DNES05, replace)

*DNES 2011
use "DNES2011_data.dta",clear	
			
gen dk_pinc = 0 if V326!=.
replace dk_pinc = 1 if V326==88
gen dk_hinc = 0 if V327!=.
replace dk_hinc = 1 if V327==88

label var dk_pinc "Personal income"
label var dk_hinc "Household income"
	
rename (dk_pinc dk_hinc) (inc#), addnumber
gen n = _n
reshape long inc, i(n)
label define _j 1 "Personal income" 2 "Household income"
label values _j _j

prtest inc,by(_j)

statsby mean=r(mean) ub=r(ub) lb=r(lb) N=r(N), by(_j) clear: ci mean inc
mylabels 0(5)15, myscale(@/100) local(yaxis) suffix("%")
twoway bar mean _j, color(gs12) barw(0.5) || rcap ub lb _j, legend(off) ylabel(`yaxis',grid gmax gmin angle(h) labsize(small)) xtitle("") xscale(range(0.6 2.4))  xlabel(1 "Personal income" 2 "Household income",labsize(small)) scheme(plotplain) ytitle("") title(2011) saving(DNES11, replace)

*DNES 2015
use "DNES2015_data.dta",clear			

gen dk_pinc = 0 if V317!=.
replace dk_pinc = 1 if V317==88
gen dk_hinc = 0 if V318!=.
replace dk_hinc = 1 if V318==88

label var dk_pinc "Personal income"
label var dk_hinc "Household income"
	
rename (dk_pinc dk_hinc) (inc#), addnumber
gen n = _n
reshape long inc, i(n)
label define _j 1 "Personal income" 2 "Household income"
label values _j _j

prtest inc,by(_j)

statsby mean=r(mean) ub=r(ub) lb=r(lb) N=r(N), by(_j) clear: ci mean inc
mylabels 0(5)15, myscale(@/100) local(yaxis) suffix("%")
twoway bar mean _j, color(gs12) barw(0.5) || rcap ub lb _j, legend(off) ylabel(`yaxis',grid gmax gmin angle(h) labsize(small)) xtitle("") xscale(range(0.6 2.4))  xlabel(1 "Personal income" 2 "Household income",labsize(small)) scheme(plotplain) ytitle("") title(2015) saving(DNES15, replace)

*Combining graphs.
gr combine DNES01.gph DNES05.gph DNES11.gph DNES15.gph, graphregion(color(white))